﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SmartWMS.Common.Extensions;
using SmartWMS.Common.ResponseOutput;
using SmartWMS.Domain.BasicsDatum;
using SmartWMS.Server.BasicsDatumServer.CarrierManagementService.Dto;
using SmartWMS.Server.BasicsDatumServer.WarehouseManagementService;
using SmartWMS.Server.BasicsDatumServer.WarehouseManagementService.Dto;

namespace SmartWMS.API.Controllers.BasicsDatumMange
{
	/// <summary>
	/// 仓库管理控制器
	/// </summary>
	[Route("api/[controller]/[action]")]
	[ApiController]
	[ApiExplorerSettings(GroupName = "BasicsDatum")]
	public class WarehouseManagementController : ControllerBase
	{
		private readonly IWarehouseManagementService _warehouseManagementService;

		public WarehouseManagementController(IWarehouseManagementService warehouseManagementService)
		{
			_warehouseManagementService = warehouseManagementService;
		}


		/// <summary>
		/// 异步显示仓库管理
		/// </summary>
		/// <param name="dto">要查询的条件</param>
		/// <returns></returns>
		[HttpPost]
		public IActionResult GetWarehouseManagermentDtoAsync(SearchDto dto)
		{
			try
			{
				var list = _warehouseManagementService.GetWarehouseManagermentDtoAsync(dto);
				return Ok(new
				{
					list.Result.totalCount,
					list.Result.pageCount,
					data = list.Result.data
				});
			}
			catch (Exception)
			{
				throw;
			}
		}

		/// <summary>
		/// 测试
		/// </summary>
		/// <returns></returns>
		[HttpPost]
		public async Task<Response<List<WarehouseDto>>> Get()
		{
			try
			{
				var list = await _warehouseManagementService.Get();
				return list;
			}
			catch (Exception)
			{
				throw;
			}
		}


		/// <summary>
		/// 新增仓库
		/// </summary>
		/// <param name="info">要添加的仓库</param>
		/// <returns>返回受影响行数</returns>
		[HttpPost]
		public async Task<Response<bool>> AddWarehouseManagerment(WarehouseDto info)
		{
			try
			{
				var result = await _warehouseManagementService.AddWarehouseManagerment(info);
				return result;
			}
			catch (Exception)
			{
				throw;
			}
		}

		/// <summary>
		/// 反填仓库管理
		/// </summary>
		/// <param name="id">要反填的Id</param>
		/// <returns>返回首行首列</returns>
		[HttpPost]
		public Response<WarehouseDto> FilWarehouseDto(WarehouseDto dto)
		{
			try
			{
				var result = _warehouseManagementService.FilWarehouseDto(dto.Id);
				return result;
			}
			catch (Exception)
			{
				throw;
			}
		}

		/// <summary>
		/// 修改仓库
		/// </summary>
		/// <param name="info">要修改的仓库实体</param>
		/// <returns></returns>
		[HttpPost]
		public async Task<Response<bool>> UpdWarehouseManagerment(WarehouseDto info)
		{
			try
			{
				var result = await _warehouseManagementService.UpdWarehouseManagerment(info);
				return result;
			}
			catch (Exception)
			{
				throw;
			}
		}

		/// <summary>
		/// 删除仓库
		/// </summary>
		/// <param name="info">要删除的仓库实体</param>
		/// <returns></returns>
		[HttpPost]
		public async Task<Response<bool>> DelWarehouseManagerment(WarehouseDto info)
		{
			try
			{
				var result = await _warehouseManagementService.DelWarehouseManagerment(info);
				return result;
			}
			catch (Exception)
			{
				throw;
			}
		}

		/// <summary>
		/// 批量删除仓库
		/// </summary>
		/// <param name="info"></param>
		/// <returns></returns>
		/// <exception cref="NotImplementedException"></exception>
		[HttpPost]
		public Task<Response<bool>> BatchDelWarehouseManagerment(WarehouseDto dto)
		{
			try
			{
				var result = _warehouseManagementService.BatchDelWarehouseManagerment(dto);
				return result;
			}
			catch (Exception)
			{
				throw;
			}
		}
	}
}
